package us.mooresr.webtroopmanager.client.ui;

import us.mooresr.webtroopmanager.client.TroopManagerService;
import us.mooresr.webtroopmanager.client.TroopManagerServiceAsync;
import us.mooresr.webtroopmanager.client.ui.AdminView.Presenter;


import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FileUpload;
import com.google.gwt.user.client.ui.FormPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent;
import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler;
import com.google.gwt.user.client.ui.FormPanel.SubmitEvent;
import com.google.gwt.user.client.ui.FormPanel.SubmitHandler;

public class ImportViewImpl extends Composite implements ImportView {
	private ImportView.Presenter presenter;

	private static ImportViewUiBinder uiBinder = GWT.create(ImportViewUiBinder.class);
	

	interface ImportViewUiBinder extends UiBinder<Widget, ImportViewImpl> {
	}
	
	@UiField(provided=true)
	FormPanel formPanel;


	@Override
	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;
		
	}
	
	public ImportViewImpl() {

		formPanel = new FormPanel();
		
		formPanel.setAction("/import");
		formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
		formPanel.setMethod(FormPanel.METHOD_POST);
		
		VerticalPanel vPanel = new VerticalPanel();
				
		FileUpload upload1 = new FileUpload();	
		upload1.setName("peopleFile");
		
		FileUpload upload2 = new FileUpload();
		upload2.setName("vehicleFile");
		
		FileUpload upload3 = new FileUpload();
		upload3.setName("eventFile");
		
		FileUpload upload4 = new FileUpload();
		upload4.setName("eventParticipantFile");
		
		FileUpload upload5 = new FileUpload();
		upload5.setName("eventDriverFile");
		
		Button submitButton = new Button("Submit");
		submitButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				formPanel.submit();
				
			}
			
		});
		
		vPanel.add(new Label("People file"));
		vPanel.add(upload1);
		vPanel.add(new Label("Vehicle file"));
		vPanel.add(upload2);
		vPanel.add(new Label("Event file"));
		vPanel.add(upload3);
		vPanel.add(new Label("Participant file"));
		vPanel.add(upload4);
		vPanel.add(new Label("Driver file"));
		vPanel.add(upload5);
		vPanel.add(submitButton);
		
		formPanel.add(vPanel);
		

		
		formPanel.addSubmitHandler(new SubmitHandler() {

			@Override
			public void onSubmit(SubmitEvent event) {
				// We can veto the submittal with event.setCancelled(true);
				
				
			}
			
		});
		
		formPanel.addSubmitCompleteHandler(new SubmitCompleteHandler() {

			@Override
			public void onSubmitComplete(SubmitCompleteEvent event) {
				// We can get the results from event.getResults()
				Window.alert(event.getResults());
				
			}
			
		});
		
		initWidget(uiBinder.createAndBindUi(this));
		
		

		
	}
}
